/* Replication file 8.28.2019*/
/* Updated file 2.18.2020*/
/* Final version 5.28.2020*/

/* Run in Stata version 15.1 */

clear
set more off

/*set a path to your downloaded data */
use  ".../DyadicConflictData.dta"


/*Our main specification drops the Cold War and World Wars*/

/*No Cold War, No World Wars*/

reg midfatyr tcresource democ_tgt dem_tgt_resource if democ_chal==0&((year<1914|year>1991)|(year>1918&year<1939)), robust 
eststo reg1
reg midfatyr tcresource democ_tgt dem_tgt_resource i.year  if democ_chal==0& ((year<1914|year>1991)|(year>1918&year<1939)), robust 
eststo reg2
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.year if democ_chal==0&((year<1914|year>1991)|(year>1918&year<1939)), robust 
eststo reg3
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.year if democ_chal==0& ((year<1914|year>1991)|(year>1918&year<1939)), robust cluster(claim)
eststo reg4
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.year if democ_chal==0&((year<1914|year>1991)|(year>1918&year<1939)), robust 
eststo reg5
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.chal i.year if democ_chal==0& ((year<1914|year>1991)|(year>1918&year<1939)), robust cluster(claim)
eststo reg6


/*esttab reg1 reg2 reg3 reg4 reg5 reg6 using "/Users/kramsay/Dropbox/War with private and public goods/JOP/latex files/Dyadic Conflict Tables/main_table.tex", ///
	replace style(tex) star($\dagger$ 0.1 * 0.05 ** 0.01 *** 0.001) title(Effect of Resources and Democracy on MID Fatalities\label{tab:Main Reg}) ///
	coeflabels(tcresource "Resources" democ_tgt "Democratic Target" dem_tgt_resource "Democratic Target $\times$ Resources" cinc_chal "CINC Score Challenger" cinc_tgt "CINC Score Target"  contigu "Contiguity" _cons "Constant") /// 
	mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6") wrap se drop (*.year *.chal ) b(3) se(3) */
	
	/*Requires minor modifications to get comments in table found in manuscript*/
	
	/* Weeks model one Personalist challenger vs machine target (MF< MH)*/

reg midfatyr tcresource if (strongmanjlw_1==1|bossjlw_1==1)&(juntajlw_2==1|machinejlw_2==1), robust  
eststo weeksa1
reg midfatyr tcresource i.year if (strongmanjlw_1==1|bossjlw_1==1)&(juntajlw_2==1|machinejlw_2==1), robust 
eststo weeksa2
reg midfatyr tcresource cinc_chal cinc_tgt contigu i.year if (strongmanjlw_1==1|bossjlw_1==1)&(juntajlw_2==1|machinejlw_2==1), robust 
eststo weeksa3

/*esttab weeksa1 weeksa2 weeksa3 using "/Users/kramsay/Dropbox/War with private and public goods/JOP/latex files/Dyadic Conflict Tables/weeksa_table.tex", ///
	replace style(tex) star($\dagger$ 0.1 * 0.05 ** 0.01 *** 0.001) title(Effect of Resources on MID Fatalities Personalist vs. Machine\label{tab:Personal Reg}) ///
	coeflabels(tcresource "Resources" cinc_chal "CINC Score Challenger" cinc_tgt "CINC Score Target"  contigu "Contiguity" _cons "Constant") /// 
	mtitles("Model 1" "Model 2" "Model 3") wrap se drop (*.year ) b(3) se(3)*/
	
	
/* Weeks model one Machine challenger vs personalist target (MH< MF)*/

reg midfatyr tcresource if (juntajlw_1==1|machinejlw_1==1)&(strongmanjlw_2==1|bossjlw_2==1), robust 
eststo weeksb1
reg midfatyr tcresource i.year if (juntajlw_1==1|machinejlw_1==1)&(strongmanjlw_2==1|bossjlw_2==1), robust 
eststo weeksb2
reg midfatyr tcresource cinc_chal cinc_tgt contigu i.year if (juntajlw_1==1|machinejlw_1==1)&(strongmanjlw_2==1|bossjlw_2==1), robust 
eststo weeksb3

/*esttab weeksb1 weeksb2 weeksb3 using "/Users/kramsay/Dropbox/War with private and public goods/JOP/data/Dyadic Conflict Tables/weeksb_table.tex", ///
	replace style(tex) star($\dagger$ 0.1 * 0.05 ** 0.01 *** 0.001) title(Effect of Resources on MID Fatalities Machine vs. Personalist\label{tab:Machine Reg}) ///
	coeflabels(tcresource "Resources" cinc_chal "CINC Score Challenger" cinc_tgt "CINC Score Target"  contigu "Contiguity" _cons "Constant") /// 
	mtitles("Model 1" "Model 2" "Model 3") wrap se drop (*.year ) b(3) se(3) */

/*Appendix Tables*/


/*Now the resutls for Pre WW-I for appendix*/

reg midfatyr tcresource democ_tgt dem_tgt_resource if democ_chal==0&(year<1914), robust 
eststo reg1PWW
reg midfatyr tcresource democ_tgt dem_tgt_resource i.year  if democ_chal==0& (year<1914), robust 
eststo reg2PWW
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.year if democ_chal==0&(year<1914), robust 
eststo reg3PWW
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.year if democ_chal==0& (year<1914), robust cluster(claim)
eststo reg4PWW
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.year i.chal if democ_chal==0&(year<1914), robust 
eststo reg5PWW
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.year if democ_chal==0& (year<1914), robust cluster(claim)
eststo reg6PWW

/*esttab reg1PWW reg2PWW reg3PWW reg4PWW reg5PWW reg6PWW using "/Users/kramsay/Dropbox (Princeton)/War with private and public goods/JOP/latex files/Dyadic Conflict Tables/preWWI_table.tex", ///
	replace style(tex) star($\dagger$ 0.1 * 0.05 ** 0.01 *** 0.001) title(Effect of Resources and Democracy on MID Fatalities\label{tab:pre-WWI Reg}) ///
	coeflabels(tcresource "Resources" democ_tgt "Democratic Target" dem_tgt_resource "Democratic Target $\times$ Resources" cinc_chal "CINC Score Challenger" cinc_tgt "CINC Score Target" contigu "Contiguity" _cons "Constant") /// 
	mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6") wrap se drop (*.year *.chal) se(3) b(3) */
	
	/*Requires minor modifications to get table*/
	
	
	
	/* Other fixed effects (mentione but not in manuscript) */
	
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.claim i.year if democ_chal==0&((year<1914|year>1991)|(year>1918&year<1939)), robust 
eststo regROBUST1
reg midfatyr tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu i.tgt i.year if democ_chal==0&((year<1914|year>1991)|(year>1918&year<1939)), robust 
eststo regROBUST2

/*esttab regROBUST1 regROBUST2 using "/Users/kramsay/Dropbox/War with private and public goods/JOP/latex files/Dyadic Conflict Tables/robust.tex", ///
	replace style(tex) star(\dagger 0.1 * 0.05 ** 0.01 *** 0.001) title(Effect of Resources and Democracy on MID Fatalities\label{tab:Main Reg}) ///
	coeflabels(tcresource "Resources" democ_tgt "Democratic Target" dem_tgt_resource "Democratic Target $\times$ Resources" cinc_chal "CINC Score Challenger" cinc_tgt "CINC Score Target" contigu "Contiguity" _cons "Constant") /// 
	mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6") wrap se drop (*.year *.tgt *.claim) se(3) b(3)*/

	
	
/* Descriptive statistics*/


/*Main model and total data set*/
 
estpost sum tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal contigu
est store alldata
estpost sum tcresource democ_tgt dem_tgt_resource cinc_tgt cinc_chal  contigu if democ_chal==0&((year<1914|year>1991)|(year>1918&year<1939))
eststo maindata 

/*esttab alldata maindata using "/Users/kramsay/Dropbox/War with private and public goods/JOP/latex files/Dyadic Conflict Tables/desc_main.tex", replace ///
cell("mean(fmt3) sd(fmt3)") nonumber nomtitle */


/* Weeks analysis */
estpost sum tcresource cinc_tgt cinc_chal contigu if (strongmanjlw_1==1|bossjlw_1==1)&(juntajlw_2==1|machinejlw_2==1)
est store persvmach
estpost sum tcresource cinc_tgt cinc_chal contigu if (juntajlw_1==1|machinejlw_1==1)&(strongmanjlw_2==1|bossjlw_2==1)
eststo machvpers 

/*esttab persvmach machvpers using "/Users/kramsay/Dropbox/War with private and public goods/JOP/latex files/Dyadic Conflict Tables/desc_weeks.tex", replace ///
cell("mean(fmt3) sd(fmt3)") nonumber nomtitle */


/*Logit estaimates*/

/*inteff command has all kinds of documented problems, so we do it ourselves*/


/* note that ## gives the estiamtes as a regular logit with interacted variable.   # does not include the individual terms */
/*for margins you need to use i. and ## because stata treats terms differently if they are just hard coded and Stata doesn't know they are indicator variables or interaction terms */
		
	logit midfatyr i.tcresource##i.democ_tgt cinc_tgt cinc_chal i.contigu if democ_chal==0& ((year<1914|year>1991)|(year>1918&year<1939)), robust cluster(claim)
	eststo logit1
		
	
	margins r.tcresource, over(r.democ_tgt) atmeans subpop(if democ_chal==0& ((year<1914|year>1991)|(year>1918&year<1939))) post/* 7.25.19 Use this for paper and  replication file*/
	eststo margins1
	
	/*The p-value here is different from the original logit because in the probability metric the values of the covariates matter.*/
		
	
		/* Result with year dummies*/
	logit  midfatyr tcresource##democ_tgt  cinc_tgt cinc_chal contigu  i.year if democ_chal==0& ((year<1914|year>1991)|(year>1918&year<1939)), robust cluster(claim)
	eststo logit2

	margins r.tcresource, over(r.democ_tgt)  subpop(if democ_chal==0& ((year<1914|year>1991)|(year>1918&year<1939))) post /*Average over all the marginals for the i observations*/
	eststo margins2
	
	/*The p-value here is different from the original logit because in the probability metric the values of te covariates matter.*/




/* esttab logit1 logit2 using "/Users/kramsay/Dropbox (Princeton)/War with private and public goods/JOP/latex files/Dyadic Conflict Tables/logit_table.tex", ///
	replace style(tex) star($\dagger$ 0.1 * 0.05 ** 0.01 *** 0.001) title(Effect of Resources and Democracy on MID Fatalities\label{tab:Logit Reg}) ///
	coeflabels(tcresource "Resources" democ_tgt "Democratic Target" dem_tgt_resource "Democratic Target $\times$ Resources" cinc_chal "CINC Score Challenger" cinc_tgt "CINC Score Target"  contigu "Contiguity" _cons "Constant") /// 
	mtitles("Model 1" "Model 2") wrap se drop ( *.year)/* *.chal)*/ b(3) se(3) */
	
/*Make a table for the marginal effects by hand*/
	
/*esttab margins1 margins2 */ 



